/**
 * 宪法管理管理初始化
 */
var Constitution = {
    id: "ConstitutionTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Constitution.initColumn = function () {
    return [
           {field: 'selectItem', radio: true},
            {title: '主键', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '宪法名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '所属分类', field: 'category', visible: true, align: 'center', valign: 'middle'},
            {title: '宪法内容', field: 'content', visible: true, align: 'center', valign: 'middle'},
            {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createtime', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '顺序', field: 'sort', visible: true, align: 'center', valign: 'middle',sortable: true}
    ];
};

/**
 * 检查是否选中
 */
Constitution.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Constitution.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加宪法管理
 */
Constitution.openAddConstitution = function () {
    var index = layer.open({
        type: 2,
        title: '添加宪法管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/constitution/constitution_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看宪法管理详情
 */
Constitution.openConstitutionDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '宪法管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/constitution/constitution_update/' + Constitution.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除宪法管理
 */
Constitution.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/constitution/delete", function (data) {
            Feng.success("删除成功!");
            Constitution.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("constitutionId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询宪法模块参数对象
 */
Constitution.formParams = function () {
    var queryData = {};
    
    queryData['name'] = $("#name").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    
    return queryData;
};

/**
 * 查询宪法管理列表
 */
Constitution.search = function () {
    Constitution.table.refresh({query: Constitution.formParams()});
};
/**
 * 搜索重置
 */
Constitution.resetSearch = function(){
	$("#name").val("");
	$("#beginTime").val("");
	$("#endTime").val("");
	
	Constitution.search();
}
$(function () {
    var defaultColunms = Constitution.initColumn();
    var table = new BSTable(Constitution.id, "/constitution/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Constitution.formParams());
    Constitution.table = table.init();
});
